package com.hot100;

@SuppressWarnings("all")
public class J010 {
    public static void main(String[] args) {
        System.out.println(convert("PAYPALISHIRING",3));
    }
    public static String convert(String s, int numRows) {
        StringBuilder[] sb = new StringBuilder[numRows];
        int len = s.length();
        if (len == 1) return s;
        int index = 0;
        while (index < len){
            for (int i=0;i<numRows;i++){
                if (sb[i] == null) sb[i] = new StringBuilder();
                if (index < len) sb[i].append(s.charAt(index++));
            }

            for (int i=numRows-2;i>0;i--){
                if (index < len) sb[i].append(s.charAt(index++));
            }
        }

        StringBuilder res = new StringBuilder();
        for (StringBuilder stringBuilder : sb) {
            res.append(stringBuilder);
        }
        return res.toString();
    }
}
